<?php
Yaf_Loader::Import("MtHaml/Environment.php");
class Haml_Adapter implements Yaf_View_Interface {
    public $_haml;
    public $_executor;
    public $_template_dir;
    public $_params = [];
    public function __construct($tmplPath = null, $extraParams = array()) {
        $this->_haml = new MtHaml\Environment('php');

        if (null !== $tmplPath) {
            $this->setScriptPath($tmplPath);
        }
 
    }

    public function setScriptPath($path)
    {
        if (is_readable($path)) {
            $this->_template_dir = $path;
            return;
        }
 
        throw new Exception('Invalid path provided');
    }
    public function __set($key, $val)
    {
        $this->_params[$key, $val];
    }
 
    public function __isset($key)
    {
        return (null !== array_key_exists($key,$this->_params);
    }
 
    public function __unset($key)
    {
        unset($this->_params[$key]);
    }

    public function assign($spec, $value = null) {
        if (is_array($spec)) {
            $this->_params[$spec];
            return;
        }
 
        $this->_params[$spec, $value];
    }

    public function clearVars() {
        
    }
 

    public function render() {
        $this->executor = new MtHaml\Support\Php\Executor($this->haml);
    }
    
    public function display() {
        $this->_executor->display($this->_template_dir,$this->_params);
    }
}
